﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Mrt.BoardGameUp.Model;

namespace MvcApp.Controllers {
	public class BoardGamesController : Controller {
		private BoardGameUpEntities db = new BoardGameUpEntities();

		//
		// GET: /BoardGames/

		public ActionResult Index() {
			var q = from bg in db.BoardGame
					orderby bg.CreateDate
					select bg;
			return View(q.ToList());
		}

		//
		// GET: /BoardGames/Details/5

		public ActionResult Details(int id) {
			return View();
		}

		//
		// GET: /BoardGames/Create

		public ActionResult Create() {
			ViewBag.UserId = new SelectList(db.User, "UserId", "Name", string.Empty);
			return View();
		}

		//
		// POST: /BoardGames/Create

		[HttpPost]
		[ValidateAntiForgeryToken]
		public ActionResult Create(BoardGame boardGame) {

			if (ModelState.IsValid) {
				boardGame.ModifyDate = boardGame.CreateDate = DateTime.Now;
				boardGame.ModifiedBy = boardGame.CreatedBy = "angry@mr-t.nl";
				db.BoardGame.Add(boardGame);
				db.SaveChanges();
				return RedirectToAction("Index");
			}

			ViewBag.UserId = new SelectList(db.User, "UserId", "Name", boardGame.UserId);
			return View(boardGame);
		}

		//
		// GET: /BoardGames/Edit/5

		public ActionResult Edit(int id) {
			return View();
		}

		//
		// POST: /BoardGames/Edit/5

		[HttpPost]
		public ActionResult Edit(int id, FormCollection collection) {
			try {
				// TODO: Add update logic here

				return RedirectToAction("Index");
			} catch {
				return View();
			}
		}

		//
		// GET: /BoardGames/Delete/5

		public ActionResult Delete(int id) {
			return View();
		}

		//
		// POST: /BoardGames/Delete/5

		[HttpPost]
		public ActionResult Delete(int id, FormCollection collection) {
			try {
				// TODO: Add delete logic here

				return RedirectToAction("Index");
			} catch {
				return View();
			}
		}
	}
}
